<?php
namespace app\open\controller;
use app\common\controller\Api;

class Useraccount extends Api {
	protected $mod = '';
	protected function _initialize() {
		parent::_initialize();
		$this->mod = model('open/UserImAccount');
	}
	/**
	 * @name 添加用户
	 */
	public function add() {
		$data = [
            'uid' => 9,
			'uname' => '测试账号9',
            'disabled' =>0
		];
		$res = $this->mod->createImUser($data);
		if ($res === false) {
			return ['code' => '20001', 'message' => $this->mod->getError()];
		} else {
			return ['code' => '00000', 'data' => ['ticket' => $res]];
		}
	}
    /**
     * @name 创建对话
     */
    public function createSation(){
        //权限验证
		$auth = self::checkApi(['type']);
        if($auth !== true) return $this->api_info;
        $res = $this->mod->createConversation($this->data);
        if($res === false){
            return ['code'=>'80400','message'=>$this->mod->getError()];
        }
        return ['code'=>'00000','data'=>$res];
    }
    
    /**
     * @name 检测对话是否存在
     */
    public function hasConversation(){
        $auth = self::checkApi(['cid']);
        if($auth !== true) return $this->api_info;
        $res = $this->mod->hasConversation(['cid'=>$this->cid],true);
        dump($res);exit;
    }
}